1
|
|
|
module.exports = function(GedcomX){ |
2
|
|
|
|
3
|
|
|
var utils = require('../utils'), |
4
|
|
|
AtomCommon = require('./AtomCommon'); |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* The content of an entry. |
8
|
|
|
* |
9
|
|
|
* @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec} |
10
|
|
|
* @see {@link https://tools.ietf.org/html/rfc4287#section-4.1.3|RFC 4287} |
11
|
|
|
* |
12
|
|
|
* @class AtomContent |
13
|
|
|
* @extends AtomCommon |
14
|
|
|
* @param {Object} [json] |
15
|
|
|
*/ |
16
|
|
|
var AtomContent = function(json){ |
17
|
|
|
|
18
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
19
|
|
|
if(!(this instanceof AtomContent)){ |
20
|
|
|
return new AtomContent(json); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
24
|
|
|
if(AtomContent.isInstance(json)){ |
25
|
|
|
return json; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
this.init(json); |
|
|
|
|
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
AtomContent.prototype = Object.create(AtomCommon.prototype); |
32
|
|
|
|
33
|
|
|
AtomContent._gedxClass = AtomContent.prototype._gedxClass = 'GedcomX.AtomContent'; |
34
|
|
|
|
35
|
|
|
AtomContent.jsonProps = [ |
36
|
|
|
'gedcomx' |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Check whether the given object is an instance of this class. |
41
|
|
|
* |
42
|
|
|
* @param {Object} obj |
43
|
|
|
* @returns {Boolean} |
44
|
|
|
*/ |
45
|
|
|
AtomContent.isInstance = function(obj){ |
46
|
|
|
return utils.isInstance(obj, this._gedxClass); |
47
|
|
|
}; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Initialize from JSON |
51
|
|
|
* |
52
|
|
|
* @param {Object} |
|
|
|
|
53
|
|
|
* @return {AtomContent} this |
54
|
|
|
*/ |
55
|
|
|
AtomContent.prototype.init = function(json){ |
56
|
|
|
|
57
|
|
|
AtomCommon.prototype.init.call(this, json); |
58
|
|
|
|
59
|
|
|
if(json){ |
60
|
|
|
this.setGedcomX(json.gedcomx); |
61
|
|
|
} |
62
|
|
|
return this; |
63
|
|
|
}; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Set the GedcomX object |
67
|
|
|
* |
68
|
|
|
* @param {GedcomX} gedcomx |
69
|
|
|
* @return {AtomContent} this |
70
|
|
|
*/ |
71
|
|
|
AtomContent.prototype.setGedcomX = function(gedcomx){ |
72
|
|
|
if(gedcomx){ |
73
|
|
|
this.gedcomx = GedcomX(gedcomx); |
74
|
|
|
} |
75
|
|
|
return this; |
76
|
|
|
}; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get the GedcomX object |
80
|
|
|
* |
81
|
|
|
* @return {GedcomX} |
82
|
|
|
*/ |
83
|
|
|
AtomContent.prototype.getGedcomX = function(){ |
84
|
|
|
return this.gedcomx; |
85
|
|
|
}; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Export the object as JSON |
89
|
|
|
* |
90
|
|
|
* @return {Object} JSON object |
91
|
|
|
*/ |
92
|
|
|
AtomContent.prototype.toJSON = function(){ |
93
|
|
|
return this._toJSON(AtomCommon, AtomContent.jsonProps); |
94
|
|
|
}; |
95
|
|
|
|
96
|
|
|
GedcomX.AtomContent = AtomContent; |
97
|
|
|
|
98
|
|
|
}; |